using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Web.Core;
using Web.Core.Providers;

namespace Web.Core.Objects
{
    public class Products
    {
        public static ArrayList GetProductsSpecial(int num, int language)
        {
            return DataProvider.GetInstance().GetProductBit(num, language, true, false, false);
        }
        public static ArrayList GetProductsPromotion(int num, int language)
        {
            return DataProvider.GetInstance().GetProductBit(num, language, false, true, false);
        }
        public static ArrayList GetProductsNewest(int num, int language)
        {
            return DataProvider.GetInstance().GetProductBit(num, language, false, false, true);
        }

        public static ArrayList GetAllProducts(int language, int pageNumber, int pageSize, string name, int manufacturer, int category, GlobalStorage.Show visible, GlobalStorage.TypeProducts special)
        {
            return DataProvider.GetInstance().GetProducts(special, category, visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, manufacturer, name, "");
        }
        public static int CountAllProducts(int language, string name, int manufacturer, int category, GlobalStorage.Show visible, GlobalStorage.TypeProducts type)
        {
            return DataProvider.GetInstance().CountProducts(type, category, visible, language, 0, manufacturer, name, "");
        }
        public static ArrayList GetAllProducts(int language, int pageNumber, int pageSize)
        {
            return DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Both, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, 0, "", "");
        }

        public static ArrayList GetAllProductsVisible(int language, int pageNumber, int pageSize)
        {
            return DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, 0, "", "");
        }

        public static ArrayList GetAllProductsByCategoryIDVisible(int language, int category, int pageNumber, int pageSize)
        {
            return DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, category, GlobalStorage.Show.Visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, 0, "", "");
        }

        public static ArrayList GetSpecialProductsVisible(int language, int pageNumber, int pageSize)
        {
            return DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.Special, 0, GlobalStorage.Show.Visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, 0, "", "");
        }

        public static ArrayList GetSpecialProductsByCategoryIDVisible(int language, int category, int pageNumber, int pageSize)
        {
            return DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.Special, category, GlobalStorage.Show.Visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, 0, "", "");
        }
        public static ArrayList GetProductSpecial(int top, int language, bool special)
        {
            return DataProvider.GetInstance().GetProductSpecial(top, language, special);

        }
        public static ArrayList GetBestSellers(int language)
        {
            return DataProvider.GetInstance().GetBestSellers(language);
        }

        public static ArrayList SearchProducts(int language, string name, string des, int manID, int pageNumber, int pageSize)
        {
            ArrayList arr = DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Visible, language, "date_added", pageNumber, pageSize, GlobalStorage.Order.Descend, 0, 0, manID, name, des);
            arr.Add(DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Visible, language, 0, manID, name, des));
            return arr;
        }

        public static Product GetProductByIDVisible(int language, int pID)
        {
            return (Product)DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Visible, language, "date_added", 1, 1, GlobalStorage.Order.Descend, pID, 0, 0, "", "")[0];
        }

        public static Product GetProductByID(int language, int pID)
        {
            return (Product)DataProvider.GetInstance().GetProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Both, language, "date_added", 1, 1, GlobalStorage.Order.Descend, pID, 0, 0, "", "")[0];
        }

        public static int CountAllProductsVisible(int language)
        {
            return DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Visible, language, 0, 0, "", "");
        }

        public static int CountAllProducts(int language)
        {
            return DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.All, 0, GlobalStorage.Show.Both, language, 0, 0, "", "");
        }

        public static int CountSpecialProductsVisible(int language)
        {
            return DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.Special, 0, GlobalStorage.Show.Visible, language, 0, 0, "", "");
        }

        public static int CountAllProductsByCategoryIDVisible(int language, int category)
        {
            return DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.All, category, GlobalStorage.Show.Visible, language, 0, 0, "", "");
        }

        public static int CountSpecialProductsByCategoryIDVisible(int language, int category)
        {
            return DataProvider.GetInstance().CountProducts(GlobalStorage.TypeProducts.Special, category, GlobalStorage.Show.Visible, language, 0, 0, "", "");
        }

        public static int InsertProduct(Product pro, ShopContent lang)
        {
            return DataProvider.GetInstance().CreateUpdateDeleteProducts(pro, lang, GlobalStorage.Action.Insert);
        }

        public static int UpdateProduct(Product pro, ShopContent lang)
        {
            return DataProvider.GetInstance().CreateUpdateDeleteProducts(pro, lang, GlobalStorage.Action.Update);
        }

        public static int DeleteProduct(Product pro)
        {
            return DataProvider.GetInstance().CreateUpdateDeleteProducts(pro, new ShopContent("", "", "", ""), GlobalStorage.Action.Delete);
        }

        public static ArrayList CalculateCurrency(ArrayList arrPro, Currency curr)
        {
            foreach (Product pro in arrPro)
                pro.Price = pro.Price * (long)curr.Rate;
            return arrPro;
        }
    }
}
